package com.train.gui;

/**
 * 
 */

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

public class TableDataAdapter extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	private String[] columnNames = new String[] {
			"车次", "发站", "到站", "历时", "商务座", "特等座", "一等座", 
			"二等座", "高级软卧", "软卧", "硬卧", "软座", "硬座",
			"无座", "其他"
		};
	private Class<?>[] classType = {};
	private ArrayList<ArrayList<Object>> rowData = new ArrayList<ArrayList<Object>>();

	public void refurbish(ArrayList<ArrayList<Object>> rows,String[] columnNames,Class<?>[] classType) {
		this.columnNames = columnNames;
		this.classType = classType;
		this.rowData = rows;
		fireTableChanged(null);
	}

	// ////////////////////////////////////////////////////////////////////////
	//
	// Implementation of the TableModel Interface
	//
	// ////////////////////////////////////////////////////////////////////////

	@Override
	public String getColumnName(int column) {
		return columnNames[column];
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return rowData.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		ArrayList<Object> row = rowData.get(rowIndex);
		return row.get(columnIndex);
	}

//	@Override
//	public Class<?> getColumnClass(int column) {
//		return classType[column];
//	}

}
